/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TestHandleProductPriceChange {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        InvoiceStatement__c invoice = new InvoiceStatement__c(Status__c = '交渉中');
        insert invoice;
        
        Merchandise__c[] products = new Merchandise__c[]{
        	new Merchandise__c(Name = 'Item 1', Description__c = 'test product 1', Price__c = 10, TotalInventory__c = 10),
        	new Merchandise__c(Name = 'Item 2', Description__c = 'test product 2', Price__c = 11, TotalInventory__c = 10)
        };
        insert products;
        
        LineItem__c[] lineItems = new LineItem__c[] {
        	new LineItem__c(InvoiceStatement__c = invoice.id, Merchandise__c = products[0].id, UnitPrice__c = 10, UnitsSold__c = 3),
        	new LineItem__c(InvoiceStatement__c = invoice.id, Merchandise__c = Products[1].id, UnitPrice__c = 11, UnitsSold__c = 6)
        };
        insert lineItems;
        
        products[0].price__c = 20;
        products[1].price__c = 5;
        Test.startTest();
        update products;
        Test.stopTest();
        
        lineItems = [SELECT id, UnitPrice__c
        			 FROM LineItem__c
        			 WHERE id
        			 IN :lineItems];
        system.assert(lineItems[0].UnitPrice__c == 10); // 変更なし
        system.assert(lineItems[1].UnitPrice__c == 5); // 製品レコード変更。項目自動更新に連動して、品目レコードの更新確認。
    }
}